import React from 'react';
import moment from 'moment';
import { DatePicker } from 'antd';

const { RangePicker } = DatePicker;

const SearchDatetime = {
  transData: (values) => {
    if (values.startTime && values.endTime) {
      return [moment(values.startTime), moment(values.endTime)];
    }
    return undefined;
  },
  render: (item, onChange) => {
    const onTimeChange = (value, dateString) => {
      onChange(
        {
          startTime: dateString[0],
          endTime: dateString[1],
        },
        item.name
      );
    };
    return (
      <div className="time-picker-box search-form-item">
        <RangePicker value={item.value} onChange={onTimeChange} size="default" />
      </div>
    );
  },
};

export default SearchDatetime;
